package com.cloudeasy.search.service;

import com.cloudeasy.api.vo.Result;
import com.cloudeasy.search.po.Post;
import com.cloudeasy.search.repository.PostRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;


@Service
public class PostService {
    private final PostRepository postRepository;

    @Autowired
    public PostService(PostRepository postRepository) {
        this.postRepository = postRepository;
    }

    public Page<Post> search(String content, Integer page, Integer size) {
        Pageable pageable = PageRequest.of(page - 1, size);
        return postRepository.findByTitleOrContentLike(content, content, pageable);
    }

    public void clear(){
        postRepository.deleteAll();
    }
}
